package workflow

import (
	hworkflow "zstackgo/pkg/header/core/workflow"
)

var (
	_ ShareFlow = &ShareFlowAbstract{
		Chain: NewShareFlowChain(),
	}
)

type ShareFlow interface {
	hworkflow.Flow
	SetChain(chain *ShareFlowChain)
	Flow(flow hworkflow.Flow)
	Done(handler hworkflow.FlowDoneHandler)
	Error(handler hworkflow.FlowErrorHandler)
	Finally(handler hworkflow.FlowFinallyHandler)
	Run(trigger hworkflow.FlowTrigger, data hworkflow.Map) error
	Rollback(trigger hworkflow.FlowRollback, data hworkflow.Map) error
	Setup()
}

type ShareFlowAbstract struct {
	Chain *ShareFlowChain
}

func (f *ShareFlowAbstract) GetName() string {
	return "ShareFlowAbstract"
}

func (f *ShareFlowAbstract) SetChain(chain *ShareFlowChain) {
	f.Chain = chain
}

func (f *ShareFlowAbstract) Flow(flow hworkflow.Flow) {
	f.Chain.Install(flow)
}

func (f *ShareFlowAbstract) Done(handler hworkflow.FlowDoneHandler) {
	f.Chain.Done(handler)
}

func (f *ShareFlowAbstract) Error(handler hworkflow.FlowErrorHandler) {
	f.Chain.Error(handler)
}

func (f *ShareFlowAbstract) Finally(handler hworkflow.FlowFinallyHandler) {
	f.Chain.Finally(handler)
}

func (f *ShareFlowAbstract) Run(trigger hworkflow.FlowTrigger, data hworkflow.Map) error {
	trigger.Next()
	return nil
}

func (f *ShareFlowAbstract) Rollback(trigger hworkflow.FlowRollback, data hworkflow.Map) error {
	trigger.Rollback()
	return nil
}

func (f *ShareFlowAbstract) Skip(data hworkflow.Map) bool {
	return false
}

func (f *ShareFlowAbstract) Setup() {
}
